package com.wyp168.jse;

/**
 * @ClassName MyPow
 * @Description TODO
 * @Author wyp168
 * @Date 2022/7/18 14:32
 */
public class MyPow {
    public static void main(String[] args) {
        System.out.println(myPow(1,-2147483648));
    }


    public static double myPow(double x, int n) {
        long N = n;

        return n >= 0 ? powSolution(x,N) : 1.0/powSolution(x,-N);
    }

    public static double powSolution(double x, long n) {
        if (n == 0) {
            return 1;
        }
        double _res = powSolution(x, n/2);
        return n % 2 == 0 ? _res * _res : _res * _res * x;
    }
}
